package duck.factory;

import duck.Quackable;
import duck.species.MallardDuck;
import duck.species.RedheadDuck;
import duck.species.RubberDuck;

public class DuckFactory {
	
	public Quackable getMallard() {
		return getDuck(MallardDuck.class);
	}
	
	public Quackable getRubber() {
		return getDuck(RubberDuck.class);
	}
	
	public Quackable getRedhead() {
		return getDuck(RedheadDuck.class);
	}

	//TODO <?>
	//TODO try - catch
	protected Quackable getDuck(Class<?> duckClass) { //throws InstantiationException, IllegalAccessException {
		try {
			return (Quackable) duckClass.newInstance();
		} catch (Exception e) {
			System.out.println("DuckFactory > getDuck > somthing was wrong with instantiating classes..");
			System.out.println(e);
			e.printStackTrace();
			return null;
		}
	}
}
